Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Weapon Check - Results in NULL Help

  1. #1
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default Weapon Check - Results in NULL Help

    Hi

    Ive tried a few different ways to check the weapon model a player is using , most seem to work when im by myself on the server , but stop working when people join, and all leave the same error

    The error shows up randomly aswell , i can go and change weapons a dozen times , and the mod will be working , ie takes disallowed weapons, leaves allowed ones alone , and the error might show up about 2 times out of the 12 , at random points , and when people are in the server , it just fills the logs and stops working

    local.player.weapon = $("arma" + local.nvezes).model (global/custom/weapons.scr, 108)
    local.player.weapon = $("arma" + local.nvezes)^

    ^~^~^ Script Error: Field 'model' applied to NULL listener




    Different Ways ive tried include

    Code:
    local.ran = randomint 9999
    self weaponcommand dual targetname ("weapon" + local.ran)
    local.player.weapon = $("weapon" + local.ran).model
    Code:
    local.weapon = $player[1] getactiveweap 0
    local.player.weapon = (local.weapon).model
    Code:
    self weaponcommand dual targetname ("weapon" + local.ran)
    local.player.weapon = $("weapon" + local.ran).model
    Code:
    local.player weaponcommand duel targetname $("weap" + local.player.entnum )
    local.player.weapon = $("weap" + local.player.entnum ).model
    Tried all of the above with same error , but all work to an extent that when im testing on server alone there fine but show error , when others are on it doesnt work at all

    Tried executing from player spawn ( tried both reborns event and state file ) with a wait 1 to give player time to get weapon ( mainly for getactive weapon one )
    or from the Raised weapons state in the mike.torso.
    Also another question if i exec from the state file , is it global or will local.player work ? bit lost if it does or not

    The above methods were taken from weapon mods , including admin pro , but all seem to give the Script error ,..

    What am i doing wrong ??

    This is the final problem of my weapon mod and its annoying me
    Last edited by Purple Elephant1au; November 25th, 2012 at 04:34 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  2. #2
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Where is your definition of local.player? To me, it doesn't sound like the problem is the weapon model, but the if local.player exists or not.

    Code:
    local.weapon = $player[1] getactiveweap 0
    local.player.weapon = (local.weapon).model
    This will obviously only work on the first player. If you tested this alone, that means $player[1] is you.

    Code:
    local.player weaponcommand duel targetname $("weap" + local.player.entnum )
    local.player.weapon = $("weap" + local.player.entnum ).model
    Should be 'dual'; this will either error or simply never work. Also remove the dollar sign as the engine will interpret it as
    if you're trying to access "$weapX" before the entity was even targetnamed with it. Not sure if you've tested this code, but
    the engine likely will targetname your weapon with "NULL".

    But unlike the previous examples, this is guaranteed to not conflict as it is a fact each player has a different client number.
    It doesn't matter how high the integer is you randomly generate, it is completely within the realm of possibility that your
    the script may assign the same targetname to two different weapons. Since computational randomness can never be true
    randomness, the possibility of this happening is even higher.

    Also, set the targetname back to "" once you've extracted the entity into a variable.
    Last edited by Sor; November 25th, 2012 at 05:37 AM.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  3. #3
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Well i dont quite know about exec it from the state file , but with the reborn spawn event local player is the person who spawned right?

    Tried adding
    local.player = parm.other
    just after main local.player:
    from the spawn event
    but doesnt without it there

    Or is that wrong

    Most based off something elgan wrote up for me on another thread, and that didnt have local.player defined , just used it after the spawn event, so thats what i used, but didnt work until i added parm.other

    Or would i spawn a trigger or something when someone spawns so when they trigger it they would be local.player.
    Last edited by Purple Elephant1au; November 25th, 2012 at 05:48 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  4. #4
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    So i should use

    Code:
    local.player weaponcommand dual targetname ("weap" + local.player.entnum )
    local.player.weapon = $("weap" + local.player.entnum ).model
    and add

    local.player weaponcommand dual targetname ""

    to the end of the script?

    EDIT:: Guess i dont add local.player weaponcommand dual targetname ""
    to the end , causes error ,

    local.player weaponcommand dual targetname "" (global/custom/weapons.scr, 132)
    local.player ^

    ^~^~^ Script Error: command 'weaponcommand' applied to NIL

    I was using examples from all over and most seem to be the same, besides the duel , dual typo , most seem to keep the $ sign tho
    Last edited by Purple Elephant1au; November 25th, 2012 at 06:21 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  5. #5
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Quote Originally Posted by Purple Elephant1au View Post
    Well i dont quite know about exec it from the state file , but with the reborn spawn event local player is the person who spawned right?
    The statefile is player specific. Thus executing from the statefile implies that the player exists but not that the player has spawned. Even if he has spawned, it doesn't necessarily mean
    that he has a weapon. That's why self is the player in scripts executed from the statefile. If the script is executed at state STAND for example, then this can mean three things:
    1. Player has entered the server as spectator, state STAND is either the first or the second state he will enter in a split second.
    2. Player has just spawned. In the split second he joined a team, your script will falsely assume he's holding his weapon already, while in reality, he isn't yet.
    3. Player has spawned and is playing.
    In the first two scenario's your code would fail as well as all components relying on that information because the player has no weapon. Checking for the player's
    team would avoid the first situation. Either way, scripts executed from the statefile and especially the STAND state will be executed several times each second,
    which is way too frequent and intensive for what you need.

    Quote Originally Posted by Purple Elephant1au View Post
    Tried adding
    local.player = parm.other
    just after main local.player:
    from the spawn event
    but normally without it there

    Or is that wrong

    Most based off something elgan wrote up for me on another thread, and that didnt have local.player defined , just used it after the spawn event, so thats what i used

    Or would i spawn a trigger or something when someone spawns so when they trigger it they would be local.player.
    What little people know is that parm.other is a global variable, which only stores the last (player) entity that triggered another entity's event. Chances that parm.other
    returns the player that just spawned, are astronomical. But this has the same problem as situation #2 I mentioned before. This event is triggered, the moment the player
    appears at the spawnpoint but at this moment he is not yet holding a gun. The solution is to keep checking until it returns something instead of nothing.

    First, I need to know what method you are currently using. Since I need to check if there aren't any other problems. This includes logical ones, because even
    if something doesn't cause an error, it doesn't mean it's correct.
    Last edited by Sor; November 25th, 2012 at 06:15 AM.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  6. #6
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    So with the state file , i exec it from when the player raises a weapon , so yes he has spawned , yes he has chosen a team and has a weapon, it also means it will work with freezetag because spawning is abit funny with it when in its spec mode,

    So if local.player would work if i exec it from state file ,i would use that when he raises a weapon , thus i can change allowed weapons mid game , but spawn event is ok and limits the amount of times the script runs

    i also do have checks in it to see if player not in spec and joined a team etc before it checks for a weapon

    I would rather use the State file

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  7. #7
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Quote Originally Posted by Purple Elephant1au View Post
    So with the state file , i exec it from when the player raises a weapon , so yes he has spawned , yes he has chosen a team and has a weapon, it also means it will work with freezetag because spawning is abit funny with it when in its spec mode,

    So if local.player would work if i exec it from state file ,i would use that when he raises a weapon , thus i can change allowed weapons mid game , but spawn event is ok and limits the amount of times the script runs

    i also do have checks in it to see if player not in spec and joined a team etc before it checks for a weapon

    I would rather use the State file
    Not my preference, but then again, it's not my mod either. I said self is local.player. So in order to do it from the RAISE state without editing existing code, add this first:
    Code:
    local.player = self
    By the way, have you tried getactiveweap in the RAISE state before?
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  8. #8
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    No i havent tried the getactiveweap from raise state , it might work better then if it was from the spawn event because from the spawn event , if the player switches weapons quick to pistol or drops weapon onto ground they can get past the check , but with the getactiveweap would i have to change it to something like

    Code:
    local.weapon = ($player + local.player.entnum ) getactiveweap 0
    local.player.weapon = (local.weapon).model
    opps or local.weapon = self getactiveweap 0
    So it doesnt only get the first person like you said before

    But it looks like ive got it working from the spawn event , but again im testing it alone
    Last edited by Purple Elephant1au; November 25th, 2012 at 06:39 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  9. #9
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    As long as you're not just referencing to yourself (i.e. $player[1]) then if it works, it should work for everyone.
    By the way:
    Code:
    local.weapon = ($player + local.player.entnum ) getactiveweap 0

    this will never work because an entity with targetname 'playerx' does not exist. For future reference, $player[local.player.entnum] will also not work.
    All you need is self for scriptfiles and the passed on local.player in spawn event scripts.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  10. #10
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Yea i thought that would be it just as i posted it that thought came to me lol

    Well Thankyou very very muchly , i got it running from the spawn event , and so far so good , no errors and everything works fine , ill just have to wait till tomorrow to fully test it out on my server.

    Oh and about setting the targetname back to "" once you've extracted the entity into a variable. How ?? i thought i would just add local.player weaponcommand dual targetname "" to the end of the script but it gave me error
    Last edited by Purple Elephant1au; November 25th, 2012 at 07:21 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •